home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / LOAD.ASM < prev    next >
Assembly Source File  |  1996-08-26  |  7KB  |  373 lines

  1. ; LOAD.ASM for E32 - Copyright (C) 1994 - 1996 Douglas Herr
  2. ;  all rights reserved
  3.  
  4. ; This subroutine prompts for a new filename.  If the
  5. ; file exists, it replaces the previous file in the buffer.
  6.  
  7. ; 02/24/1996 DH: added default '*.*' in current directory if
  8. ;                no existing filename
  9.  
  10. ; 03/29/1996 DH: input filename with wildcard character runs ASM32:MarkFile
  11. ;                via file_list instead of ASM32:PickFile
  12.  
  13. include    model.inc
  14.  
  15. public    load, edit_filename
  16. extrn    qfname:near, tprintce:near, strlen:near
  17. extrn    strchr:near, menuoption:near
  18. extrn    strnchr:near, tedit:near
  19. extrn    clearkey:near, getkey:near
  20. extrn    strrchr:near, stricmp:near
  21. extrn    error:near
  22.  
  23. extrn    new:near
  24. extrn    yesno_message:near
  25. extrn    swap_files:near
  26. extrn    file_list:near
  27.  
  28. extrn    number_of_files:abs
  29. extrn    file_data_ptr:dword
  30. extrn    file_data_len:abs
  31.  
  32. temp_filename    equ    byte ptr [ebp-64]
  33.  
  34. include    dataseg.inc
  35.  
  36. ; data for LOAD
  37. extrn    filename:dword
  38. extrn    dirty_bits:byte, rows:byte, warning:byte, inverse:byte
  39. extrn    verify_msg:byte
  40. star_dot_star    db '*.*',0
  41. load_mess    db ' Load: ',0
  42. load_len    equ $-load_mess-1
  43.  
  44. ; data for READFILE
  45. extrn    display_mode:byte
  46. extrn    file_read_error:byte
  47. extrn    filesel:word
  48. extrn    filesiz:dword            ; file size
  49. extrn    buffersiz:dword
  50. extrn    dirty_bits:byte
  51. extrn    cur_posn:byte            ; really a word
  52. no_file        db 'file not found',0
  53. @curseg    ends
  54.  
  55. include    codeseg.inc
  56. load    proc    near
  57.     enter    64,0
  58.     cld
  59.     mov    esi,filename        ; point to existing filename
  60.  
  61. ; if no existing filename, default to '*.*' in current directory
  62.     mov    ebx,esi
  63.     call    strlen
  64.     test    ecx,ecx
  65.     jnz    short l0
  66.     lea    ebx,star_dot_star
  67.     call    qfname            ; ret: ESI -> drive:\path\*.*
  68.  
  69. ; copy filename to temporary buffer
  70. l0:    lea    edi,temp_filename
  71.     push    ss
  72.     pop    es
  73.     mov    ecx,64/4
  74.     rep    movsd
  75.  
  76.     test    dirty_bits,10000000b    ; has the file has been changed?
  77.     jz    short l1
  78.     mov    ah,warning
  79.     lea    esi,verify_msg
  80.     call    yesno_message
  81.     cmp    al,'N'
  82.     je    load_exit
  83.  
  84. l1:
  85. prompt_for_load:
  86.     mov    esi,offset load_mess
  87.     call    edit_filename
  88.     cmp    ax,27            ; Esc key?
  89.     je    load_exit
  90.  
  91. ; qualify the filename
  92. l2:    mov    ebx,esi            ; DS:[EBX] points to filename
  93.     call    qfname
  94.     mov    edi,ebx
  95.     push    ds
  96.     pop    es
  97.     cld
  98.     rep    movsb        ; copy qualified filename to buffer
  99.     mov    al,cl
  100.     stosb
  101.  
  102. ; look for wildcard characters
  103.     lea    ebx,temp_filename    ; DS:[EBX] points to filename
  104.     mov    al,'?'        ; look for wildcard characters
  105.     call    strchr        ; returns with CX = string length
  106.     jnc    short load01    ; if CF = 0, found the '?' character
  107.     mov    al,'*'        ;  else look for '*'
  108.     call    strnchr
  109.     jc    short load02        ; no wildcards if CF = 1
  110. load01:
  111. ; print qualified filespec
  112.     mov    esi,ebx
  113.     mov    dh,rows
  114.     inc    dh
  115.     mov    dl,load_len
  116.     mov    ah,inverse
  117.     call    tprintce
  118.     call    file_list
  119. ;    jmp    short load_exit
  120.     cmp    ax,0Dh
  121.     je    prompt_for_load        ; continue if Enter pressed
  122.     jmp    short load_exit
  123.  
  124. load02:
  125.     lea    edx,temp_filename
  126.     call    ok_to_load        ; can I load this file?
  127.     jc    prompt_for_load
  128.  
  129.     and    dirty_bits,01111111b
  130.     call    new
  131.     lea    edx,temp_filename
  132.     call    _readfile        ; skip ok_to_load
  133.     jc    l1            ; ask for new filename if error
  134.  
  135. ; copy temporary filename to file buffer
  136.     mov    edi,filename
  137.     lea    esi,temp_filename
  138.     push    ds
  139.     push    ds
  140.     pop    es            ; ES:[EDI] -> filename buffer
  141.     push    ss
  142.     pop    ds            ; DS:[ESI] -> temporary buffer
  143.     mov    ecx,64/4
  144.     rep    movsd
  145.     pop    ds
  146.     or    dirty_bits,1
  147. load_exit:
  148.     clc
  149.     leave
  150.     ret
  151.  
  152. load    endp
  153.  
  154.  
  155. edit_filename:
  156.     or    dirty_bits,00010000b    ; re-do FKey display
  157.     mov    dh,rows
  158.     inc    dh        ; last row of screen
  159.     xor    dl,dl
  160.     mov    ah,inverse
  161.     call    tprintce    ; print prompt string
  162.     add    dl,cl
  163.     lea    esi,temp_filename
  164.     mov    ecx,63
  165.     mov    al,01000b    ; clear input string if first key
  166.                 ; not cursor control
  167.     call    tedit
  168.     ret
  169.  
  170.  
  171. ; READFILE.ASM for E32 - Copyright (C) 1994 - 1996 Douglas Herr
  172. ;  all rights reserved
  173.  
  174. ; call with DS:[EDX] -> ASCIIZ filename
  175.  
  176. ; 02/24/1996 DH: added checking for subdirectory if file not exist
  177.  
  178.  
  179. CR    equ    0Dh
  180. LF    EQU    0Ah
  181.  
  182. public    readfile
  183. extrn    fexist:near, subexist:near
  184. extrn    working:near
  185. extrn    fileloadfar:near
  186. extrn    display_screen:near
  187. extrn    display_hex:near
  188.  
  189. extrn    error:near
  190.  
  191. readfile    proc    near
  192.     call    ok_to_load        ; is this a loadable file?
  193.     jc    short exit        ;  no, ret to prompt
  194.  
  195. _readfile:
  196.     call    is_loaded        ; file already loaded?
  197.     jc    short _rf0        ;  no, read it
  198.     call    swap_files
  199.     mov    fs,filesel
  200.     ret
  201.  
  202. _rf0:
  203.     call    working
  204.     call    fileloadfar
  205.     jnc    short r1
  206.     lea    edx,file_read_error
  207.     jmp    short bad_exit
  208. r1:
  209.     xchg    bx,filesel        ; get old selector in BX
  210.     mov    filesiz,eax
  211.     mov    buffersiz,eax
  212.     sys    RelMem
  213.     or    dirty_bits,00100000b
  214.     call    is_it_hex
  215.     sbb    eax,eax
  216.     mov    ah,al
  217.     inc    al
  218.     not    ah
  219.     shl    al,2
  220.     mov    display_mode,al
  221.     and    ah,10
  222.     mov    cur_posn,ah
  223.     clc
  224.     mov    fs,filesel
  225. exit:
  226.     ret
  227.  
  228. bad_exit:
  229.     call    error
  230.     ret
  231.  
  232.  
  233. alphanum    equ    dword ptr [ebp-4]
  234. notalpha    equ    dword ptr [ebp-8]
  235.  
  236. is_it_hex:
  237.     enter    8,0
  238.     push    es
  239.     mov    ecx,100h
  240.     cmp    filesiz,ecx
  241.     jae    size_ok
  242.     mov    ecx,filesiz
  243. size_ok:
  244.     jecxz    short end_test
  245.     mov    es,filesel
  246.     assume    es:nothing
  247.     mov    edx,-1
  248.     mov    ebx,filesiz
  249.     push    ecx
  250.     call    test_it
  251.     pop    ecx
  252.     jnc    end_test
  253.     mov    ebx,edx            ; EBX = -1
  254.     neg    edx            ; EDX = 1
  255.     call    test_it
  256.  
  257. end_test:
  258.     pop    es
  259.     leave
  260.     ret
  261.  
  262. test_it:
  263.     xor    eax,eax
  264.     mov    alphanum,eax
  265.     mov    notalpha,eax
  266. test_byte:
  267.     add    ebx,edx
  268.     mov    al,es:[ebx]
  269.     cmp    al,'z'
  270.     ja    short its_not_alpha
  271.     cmp    al,0Dh
  272.     je    short its_alpha
  273.     cmp    al,0Ah
  274.     je    short its_alpha
  275.     cmp    al,' '
  276.     jb    short its_not_alpha
  277.  
  278. its_alpha:
  279.     inc    alphanum
  280.     loop    test_byte
  281.     jmp    short compare
  282.  
  283. its_not_alpha:
  284.     inc    notalpha
  285.     loop    test_byte
  286.  
  287. compare:
  288.     mov    eax,notalpha
  289.     cmp    eax,alphanum
  290.     ret
  291.  
  292. readfile    endp
  293.  
  294.  
  295. ;
  296. ; test filename for load
  297. ; call with DS:[EDX] -> filename
  298. ;
  299. ok_to_load:
  300.     call    fexist        ; file exist?
  301.     jnc    short ok9    ;  yup, proceed
  302.     call    subexist    ; is it a sub?
  303.     jc    short ok1    ;  no, do error stuff
  304.     mov    ebx,edx        ; filename ptr
  305.     call    strlen        ;  else add '*.*' to path & re-prompt
  306.     mov    edi,ebx
  307.     add    edi,ecx
  308.     mov    al,'\'
  309.     cmp    [edi-1],al    ; have trailing backslash?
  310.     je    short ok0    ;  yup, don't add one
  311.     stosb            ;  else add trailing backslash
  312. ok0:    
  313.     lea    esi,star_dot_star
  314.     movsd            ; append '*.*' to end of path
  315.     jmp    short ok8
  316. ok1:
  317.     lea    edx,no_file    ; error message in READFILE.ASM
  318.     call    error
  319. ok8:
  320.     stc
  321. ok9:
  322.     ret
  323.  
  324. ;
  325. ; see if file is already loaded
  326. ; call with DS:[EDX] -> filename
  327. ;
  328. is_loaded:
  329.  
  330.     pushad
  331.     push    es
  332.     mov    eax,ds
  333.     mov    es,eax
  334.  
  335.     mov    esi,file_data_ptr
  336.     mov    edi,edx            ; ES:[EDI] -> filename to check
  337.     mov    ecx,number_of_files
  338.     mov    edx,file_data_len
  339.     xor    eax,eax
  340.     xor    ebx,ebx            ; record index
  341. loaded0:
  342.     push    esi
  343.     mov    esi,[esi]        ; filename ptr
  344.     cmp    esi,-1            ; empty buffer?
  345.     je    short empty
  346.     cmp    byte ptr [esi],0    ; NUL filename?
  347.     je    short empty        ;  new file, or empty
  348.     call    stricmp            ; compare name with file to load
  349.     pop    esi
  350.     je    short loaded8        ; file IS loaded, exit
  351.     push    esi
  352. empty:
  353.     pop    esi
  354. loaded1:
  355.     add    esi,edx            ; point to next record
  356.     inc    ebx            ; record index
  357.     loop    loaded0
  358.     stc                ; file not loaded, set CF
  359.     jmp    short loaded9
  360.  
  361.  
  362. ; file IS loaded, clear CF
  363. loaded8:
  364.     clc
  365. loaded9:
  366.     pop    es
  367.     mov    [StackEBX],ebx
  368.     popad
  369.     ret
  370.  
  371. @curseg    ends
  372.     end
  373.